/*
 * @Author: 0x9DEFA478
 * @Date: 2025-08-12 22:41:06
 * @LastEditTime: 2025-09-22 23:45:38
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#include "./H_String.hpp"
#include <sstream>
#include <stdarg.h>
#include "./H_StringFormat.h"




namespace H{

  namespace String{

    bool IsSuffix(const std::string& String,const std::string& Suffix,bool CaseInsensitive){
      auto stringLen=String.length();
      auto suffixLen=Suffix.length();

      if(stringLen<suffixLen){
        return false;
      }

      if(!CaseInsensitive){
        while((stringLen>0)&&(suffixLen>0)){
          stringLen--;
          suffixLen--;
          if(String[stringLen]!=Suffix[suffixLen]){
            return false;
          }
        }
      }else{
        while((stringLen>0)&&(suffixLen>0)){
          stringLen--;
          suffixLen--;
          char c0=String[stringLen];
          char c1=Suffix[suffixLen];
          if((c0>='A')&&(c0<='Z')){
            c0+='a'-'A';
          }
          if((c1>='A')&&(c1<='Z')){
            c1+='a'-'A';
          }
          if(c0!=c1){
            return false;
          }
        }
      }

      return true;
    }

    struct Format_CharOutput{
      H_StringFormat_CharOutput CharOutput;
      std::stringstream ss;
    };

    static int Output(H_StringFormat_CharOutput* CharOutput,char c){
      Format_CharOutput* format_CharOutput;

      format_CharOutput=cH_GetParentPointer(CharOutput,Format_CharOutput,CharOutput);

      format_CharOutput->ss<<c;

      return 0;
    }

    CheckPrintfFormat(0,1) std::string Format(const char* Format,...){
      va_list Params;
      Format_CharOutput CharOutput;

      CharOutput.CharOutput.Output=Output;
      
      va_start(Params,Format);

      (void)H_StringFormat(&CharOutput.CharOutput,Format,&Params);

      va_end(Params);

      return CharOutput.ss.str();
    }

  }

}



